<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Widgets for displaying a list of editing profile users.
 * Includes a list widget and its specific item widget.
 * 
 * Show the items in the list, and some reaction button as
 * 'edit' and 'delete', 'block'?..
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.2
 * 
 * 0.2)  Inherited from the BaseList and BaseListItem
 * 0.3)  Changes its name to 'profile'
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_list.php';

/**
 * Widget for displaying a list of profiles.
 */
class ProfileList extends BaseList
{
	/**
	 * Overrided.
	 * Starts a profile user list.
	 */
	function showStart()
	{
		// The List title.
		$this->out->element('h3', null, '社联会用户');
		$this->out->elementStart('ol', array('class' => 'cls_ol_list'));
		
		$this->out->element('hr');
	}
	
	/**
	 * Ends a list.
	 */
	function showEnd()
	{
		$this->out->elementEnd('ol');
	}
	
	/**
	 * Overrided.
	 * Returns a list item for the current profile user.
	 */
	function newListItem(&$obj)
	{
		return new ProfileListItem($obj, $this->out);
	}
}

/**
 * Widget for displaying a single profile with some options.
 */
class ProfileListItem extends BaseListItem
{
	/**
	 * Do some data preparation.
	 */
	function prepareData()
	{
		$this->optionswitch = Rights::hasRight(slh_get_userrights(), RIGHT_DATA);
	}
	
	/**
	 * Start a single profile item.
	 */
	function showStart()
	{
		/*
		$this->out->elementStart('dd', array('class' => 'cls_dd_useritem'));
		
		$this->out->elementStart('fieldset');
		$legend = 'user id: ' . $this->obj->user_id;
		$this->out->element('legend', null, $legend);
		*/
		$this->out->elementStart('li', array('class' => 'cls_div_entry'));
	}
	
	function showEnd()
	{
		$this->out->elementEnd('li');
		
		$this->out->element('hr');
	}
	
	function showDataInfo()
	{
		$this->out->raw('<span class="cls_span_realname">' .
						$this->obj->realname .
						'</span>');
		
		$this->out->raw('<span class="cls_span_department">' .
						$this->obj->department .
						'</span>');
	}
	
	function showOptions()
	{
		$this->out->elementStart('div', 'cls_div_profileoptions');
		
		$this->out->elementStart('ul', array('class' => 'cls_ul_inline'));
			$this->out->elementStart('li');
			$this->out->element('a', array('href' => slh_action2url('editprofileuser',
								  	   							  	array('guser_id' => $this->obj->user_id)),
										   'title'=> '编辑该用户!'),
								'编辑');
			$this->out->elementEnd('li');
			
			if (true) {
			$this->out->elementStart('li');
			$this->out->element('a', array('href' => slh_action2url('deleteprofileuser',
								  	   							  	array('guser_id' => $this->obj->user_id)),
										   'title'=> '把这个用户删掉哈!'),
								'删除');
			$this->out->elementEnd('li');
			}
		$this->out->elementEnd('ul');
		
		$this->out->elementEnd('div');
	}
	
}

?>